package com.example.yl.myapplication22222222222;

import android.app.Instrumentation;
import android.graphics.Color;
import android.os.SystemClock;
import android.support.test.filters.SmallTest;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import android.widget.EditText;

/**
 * Created by yl on 2018/4/30.
 */

public class TestIn2 extends ActivityInstrumentationTestCase2<MainActivity> {

    private MainActivity activity;
    private Button button;
    private EditText edit;
    private Instrumentation instrumentation;
    private Instrumentation.ActivityMonitor monitor;

    public TestIn2() {
        super(MainActivity.class);
    }

    public TestIn2(String pkg, Class<MainActivity> activityClass) {
        super(pkg, activityClass);
    }

    public TestIn2(Class<MainActivity> activityClass) {
        super(activityClass);
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
        instrumentation = getInstrumentation();
        button = activity.findViewById(R.id.bt1);
        edit = activity.findViewById(R.id.edit_aa);
    }

    @SmallTest
    public void testAbcc() throws InterruptedException {
        instrumentation.runOnMainSync(new ClickThread());
        MainActivity_1 mainActivity_1 = (MainActivity_1) instrumentation.waitForMonitorWithTimeout(monitor, 1000);
        instrumentation.removeMonitor(monitor);
        assertNotNull("MainActivity_1==null", mainActivity_1);
        EditText edit2 = mainActivity_1.findViewById(R.id.edit_aa);
        edit2.setText(">>>>>>>>>>>>>>>>>>>>>>>>>");
        SystemClock.sleep(3000);
    }

    private class ClickThread implements Runnable {

        @Override
        public void run() {
            edit.setTextColor(Color.parseColor("#965D0E"));
            edit.setText("你>>>>>>>");
            monitor = instrumentation.addMonitor(MainActivity_1.class.getName(), null, false);
            button.performClick();

        }
    }
}
